﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class kuaidixinxi_add : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		if (!IsPostBack)
        {
            Random rnd = new Random();
            int n = rnd.Next(1000, 9999);
            string newname = DateTime.Now.Year.ToString().Trim() + DateTime.Now.Month.ToString().Trim() + DateTime.Now.Day.ToString().Trim() + DateTime.Now.Hour.ToString().Trim() + DateTime.Now.Minute.ToString().Trim() + DateTime.Now.Second.ToString().Trim() + n.ToString().Trim();
            yundanhao.Text = newname;

            tijiaoren.Text = Session["username"].ToString().Trim();
            kuaijianleixing.Items.Add("普通");
            kuaijianleixing.Items.Add("特快");

            dangqianzhuangtai.Items.Add("未发货");
            dangqianzhuangtai.Items.Add("传递途中");
            dangqianzhuangtai.Items.Add("已到货");
            shengfen.Items.Add("请选择");
            shengfen2.Items.Add("请选择");
            addxiala("shengfenxinxi", "shengfen", "kehubianhao");
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string sql;
        sql="insert into kuaidixinxi(yundanhao,kuaijianleixing,yuandizhi,mudedi,shoujianrenxingming,shoujianrendianhua,jiage,dangqianzhuangtai,beizhu,tijiaoren) values('"
            +yundanhao.Text.ToString().Trim()+"','"+kuaijianleixing.Text.ToString().Trim()+"','"+yuandizhi.Text.ToString().Trim()+"','"+mudedi.Text.ToString().Trim()+"','"+shoujianrenxingming.Text.ToString().Trim()+"','"+shoujianrendianhua.Text.ToString().Trim()+"','"+jiage.Text.ToString().Trim()+"','"+dangqianzhuangtai.Text.ToString().Trim()+"','"+beizhu.Text.ToString().Trim()+"','"+tijiaoren.Text.ToString().Trim()+"') ";

        int result;
        result = new Class1().hsgexucute(sql);
        if (result == 1)
        {
            Response.Write("<script>javascript:alert('添加成功');</script>");
        }
        else
        {
            Response.Write("<script>javascript:alert('系统错误，请检查数据库设置问题');</script>");
        }
    }
    private void addxiala(string ntable, string nzd, string nxlk)
    {
        string sql;
        sql = "select " + nzd + " from " + ntable + " order by id desc";
        DataSet result = new DataSet();
        result = new Class1().hsggetdata(sql);
        if (result != null)
        {
            if (result.Tables[0].Rows.Count > 0)
            {
                int i = 0;
                for (i = 0; i < result.Tables[0].Rows.Count; i++)
                {
                    shengfen.Items.Add(result.Tables[0].Rows[i][0].ToString().Trim());
                    shengfen2.Items.Add(result.Tables[0].Rows[i][0].ToString().Trim());
                }
            }
        }
    }
    protected void shengfen_SelectedIndexChanged(object sender, EventArgs e)
    {
        shixian.Items.Clear();
        string sql;
        sql = "select shixian from shixianxinxi where shengfen='" + shengfen.Text.ToString().Trim() + "'";

        DataSet result = new DataSet();
        result = new Class1().hsggetdata(sql);
        if (result != null)
        {
            if (result.Tables[0].Rows.Count > 0)
            {
                int i = 0;
                for (i = 0; i < result.Tables[0].Rows.Count; i++)
                {
                    shixian.Items.Add(result.Tables[0].Rows[i][0].ToString().Trim());
                }
            }
        }
        yuandizhi.Text = shengfen.Text + shixian.Text;
    }
    protected void shixian_SelectedIndexChanged(object sender, EventArgs e)
    {
        yuandizhi.Text = shengfen.Text + shixian.Text;
    }
    protected void shengfen2_SelectedIndexChanged(object sender, EventArgs e)
    {
        shixian2.Items.Clear();
        string sql;
        sql = "select shixian from shixianxinxi where shengfen='" + shengfen2.Text.ToString().Trim() + "'";

        DataSet result = new DataSet();
        result = new Class1().hsggetdata(sql);
        if (result != null)
        {
            if (result.Tables[0].Rows.Count > 0)
            {
                int i = 0;
                for (i = 0; i < result.Tables[0].Rows.Count; i++)
                {
                    shixian2.Items.Add(result.Tables[0].Rows[i][0].ToString().Trim());
                }
            }
        }
        mudedi.Text = shengfen2.Text + shixian2.Text;
    }
    protected void shixian2_SelectedIndexChanged(object sender, EventArgs e)
    {
        mudedi.Text = shengfen2.Text + shixian2.Text;
    }
}

